package com.tanhua.server.controller;

import cn.hutool.core.util.StrUtil;
import com.tanhua.server.vo.CommentVo;
import com.tanhua.dubbo.vo.PageInfo;
import com.tanhua.server.service.QuanZiApiService;
import com.tanhua.server.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("comments")
public class CommentController {

    @Autowired
    private QuanZiApiService quanZiApiService;

    @GetMapping
    public PageResult getCommentList(@RequestParam(value = "movementId") String movementId,
                                                @RequestParam(value = "page", defaultValue = "1") String page,
                                                @RequestParam(value = "pageSize", defaultValue = "10") String pageSize) {
        return this.quanZiApiService.getCommentList(movementId, page, pageSize);
    }

    @PostMapping
    public Boolean saveComment(@RequestBody Map<String, String> param) {
        String movementId = param.get("movementId");
        String comment = param.get("comment");
        if(StrUtil.isAllNotEmpty(movementId, comment)) {
            return this.quanZiApiService.saveComment(movementId, comment);
        }
        return false;
    }

    /**
     * 点赞
     *
     * @param commentId
     * @return
     */
    @GetMapping("/{id}/like")
    public Long likeComment(@PathVariable("id") String commentId) {
        return this.quanZiApiService.likeComment(commentId);
    }

    /**
     * 取消点赞
     *
     * @param commentId
     * @return
     */
    @GetMapping("/{id}/dislike")
    public Long disLikeComment(@PathVariable("id") String commentId) {
        return this.quanZiApiService.disLikeComment(commentId);
    }
}
